<?

class Qi_Form_Field_CheckGrid extends Qi_Form_Field
{
	protected $inline = false;
	public $type = null;
	public $_label_acima = true;
	private $_horizontal = array();
	private $_vertical = array();

	public function __construct($horizontal, $vertical)
	{
		$this->_horizontal = $horizontal;
		$this->_vertical = $vertical;
	}

	public function render()
	{
		$htm = "\n<table>\n";
		$htm .= "\t<thead>\n";
		$htm .= "\t\t<tr>\n";
		$htm .= "\t\t\t<th>\n";
		$htm .= "\t\t\t</th>\n";

		foreach($this->_horizontal as $k => $v):
			$htm .= "\t\t\t<th>\n";
			$htm .= str_repeat("\t", 4) . h($v);
			$htm .= "\n\t\t\t</th>\n";
		endforeach;

		$htm .= "\t\t</tr>\n";
		$htm .= "\t</thead>\n";

		$htm .= "\t<tbody>\n";

		foreach($this->_vertical as $vk => $vv):
			$htm .= "\t\t<tr>\n";
			$htm .= "\t\t\t<td>\n";
			$htm .= str_repeat("\t", 4) . h($vv);
			$htm .= "\n\t\t\t</td>\n";

			foreach($this->_horizontal as $hk => $hv):
				$htm .= "\t\t\t<td>\n";
				$htm .= str_repeat("\t", 4) . <<<INPUT
<input type="checkbox" name="{$this->name}[$vk][$hk]" value="1" />
INPUT;
				$htm .= "\n\t\t\t</td>\n";
			endforeach;

			$htm .= "\t\t</tr>\n";
		endforeach;

		$htm .= "\t</tbody>\n";
		$htm .= "</table>\n";
		return $htm;
	}
}

?>